package com.example.baserecyclerviewadapterdemo.adapter;

import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.entity.ClickEntity;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ItemClickAdapter extends BaseMultiItemQuickAdapter<ClickEntity, BaseViewHolder> implements OnItemClickListener, OnItemChildClickListener {
    private AnimationAdapter mAdapter;

    public AnimationAdapter getAdapter() {
        return mAdapter;
    }

    public void setAdapter(AnimationAdapter mAdapter) {
        this.mAdapter = mAdapter;
    }

    public ItemClickAdapter(@Nullable List<ClickEntity> data) {
        super(data);
        addItemType(ClickEntity.CLICK_ITEM_VIEW, R.layout.item_click_view);
        addItemType(ClickEntity.CLICK_ITEM_CHILD_VIEW,R.layout.click_item_child_view2);
        addItemType(ClickEntity.NEST_CLICK_ITEM_CHILD_VIEW,R.layout.item_nest_click);
        //addChildClickViewIds(R.id.btn);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, ClickEntity clickEntity) {
        /*if (holder.getItemViewType() == ClickEntity.NEST_CLICK_ITEM_CHILD_VIEW) {
            RecyclerView recyclerView = holder.getView(R.id.nest_list);
            recyclerView.setHasFixedSize(true);
            if (recyclerView.getLayoutManager() == null) {
                recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            }
            recyclerView.setAdapter(mAdapter);
        }*/
    }

    @Override
    public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
        Toast.makeText(getContext(), "childView click", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        Toast.makeText(getContext(), "嵌套RecycleView item 收到: " + "点击了第 " + position + " 一次", Toast.LENGTH_SHORT).show();
    }
}
